package com.reebake.ideal.infra;

import com.reebake.ideal.jdbc.FlywayUtil;
import org.flywaydb.core.Flyway;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@ComponentScan(basePackageClasses = InfraAutoConfiguration.class)
@Configuration
public class InfraAutoConfiguration {
    @Bean
    MapperScannerConfigurer infraMapperScannerConfigurer() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setBasePackage(InfraAutoConfiguration.class.getPackageName() + ".mapper");
        return mapperScannerConfigurer;
    }

    @Bean
    Flyway infraFlyway(DataSource dataSource) {
        String schema = "infra";
        return FlywayUtil.migrate(dataSource, schema);
    }

}
